package opreation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOpreation implements IOpreation{
    @Override
    public void work(BookList booklist) {
        System.out.println("归还图书");
        System.out.println("请输入你要归还的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = booklist.getUsedsize();
        int i =0;
        for (i=0; i < size; i++) {
            Book book = booklist.getBooks(i);
            if(book.getName().equals(name)) {
                break;
            }
        }
        if(i>=size) {
            System.out.println("没有该书，无需归还");
            return;
        }
        Book book = booklist.getBooks(i);

        book.setBorrow(false);
        System.out.println("归还成功！");
    }
}
